package com.oazon.moco.link.lan;

import java.util.Arrays;
import java.util.List;

import io.netty.channel.ChannelHandlerContext;
import android.util.Log;

import com.oazon.moco.lan.core.http.bean.AllSatus;
import com.oazon.moco.lan.core.http.bean.AllStateInstance;
import com.oazon.moco.lan.core.http.bean.MediaStateInstance;
import com.oazon.moco.lan.core.http.bean.PositionInfo;
import com.oazon.moco.lan.core.http.bean.ResponseVolume;
import com.oazon.moco.lan.core.http.bean.SongInfo;
import com.oazon.moco.lan.core.http.bean.ZoneInfo;
import com.oazon.moco.link.core.LinkEvent;
import com.oazon.moco.link.core.LinkEventListener;
import com.oazon.moco.link.core.source.LanEventSource;
import com.oazon.moco.link.core.source.LinkEventSource;
import com.oazon.moco.link.event.ResponceEvent;
import com.oazon.moco.link.event.ResponceStatus;

public class ResponceEventListener extends LinkEventListener {

	private static final String TAG = "ResponceEventListener";
	
	public ResponceEventListener(LinkEventSource... sources){
		setBlackList(Arrays.asList(sources));
	}
	
	@Override
	public void onLinkEvent(LinkEvent event) {
		if(!filter((LinkEventSource)event.getSource())||!(event instanceof ResponceEvent)){
			return;
		}
		ChannelHandlerContext ctx = null;
		ResponceEvent responceEvent = (ResponceEvent) event;
		if(event.getSource() instanceof LanEventSource){
			ctx = ((LanEventSource)event.getSource()).getChannelContext();
		}
	
		if(responceEvent.getResponceStatus() == ResponceStatus.VERSION){
			responseZoneInfo(responceEvent.getZoneInfo(),ctx);
			
		}else if(responceEvent.getResponceStatus() == ResponceStatus.PLAY_STATUS){
			responsePlayStatus(responceEvent.getPlayStatus(),ctx);
			
		}else if(responceEvent.getResponceStatus() == ResponceStatus.CATEGORY){
			responseCategory(responceEvent.getCategory(),ctx);
			
		}else if(responceEvent.getResponceStatus() == ResponceStatus.VOLUME){
			responseVolume(responceEvent.getVolume(),ctx);
			
		}else if(responceEvent.getResponceStatus() == ResponceStatus.PLAY_MODE){
			responsePlayMode(responceEvent.getPlaymode(),ctx);
			
		}else if(responceEvent.getResponceStatus() == ResponceStatus.POSITION_INFO){
			responsePositionInfo(responceEvent.getPositionInfo(),ctx);
			
		}else if(responceEvent.getResponceStatus() == ResponceStatus.ALL_STATUS){
			responseAllStatus(responceEvent.getInstances(),ctx);
			
		}else if(responceEvent.getResponceStatus() == ResponceStatus.SONGINFO){
			responseSongInfo(responceEvent.getSonginfo(),ctx);
		}
	}

	protected void responsePositionInfo(PositionInfo positionInfo,
			ChannelHandlerContext ctx) {
		
	}

	protected void responseZoneInfo(ZoneInfo zoneInfo, ChannelHandlerContext ctx) {
		
	}

	protected void responseSongInfo(SongInfo songinfo,ChannelHandlerContext ctx) {
		Log.i(TAG, "响应songInfo+"+songinfo.getName());
		
	}

	protected void responseAllStatus(MediaStateInstance instances,ChannelHandlerContext ctx) {
		Log.i(TAG, "响应Allstatus+"+instances.toString());
		
	}

	protected void responsePlayMode(String playmode,ChannelHandlerContext ctx) {
		Log.i(TAG, "响应playmode+"+playmode);
		
	}

	protected void responseVolume(ResponseVolume responseVolume,ChannelHandlerContext ctx) {
		Log.i(TAG, "响应volume+"+responseVolume.getMaster());
		
	}

	protected void responseCategory(String category,ChannelHandlerContext ctx) {
		Log.i(TAG, "响应category+"+category);
		
	}

	protected void responsePlayStatus(String playStatus,ChannelHandlerContext ctx) {
		Log.i(TAG, "响应playStatus+"+playStatus);
		
	}
}
